home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 12 / Amiga Format AFCD12 (Apr 1997, Issue 96).iso / -in_the_mag- / html_tutorial / pr.cpp < prev    next >
C/C++ Source or Header  |  1997-01-21  |  1KB  |  57 lines

  1. #include <iostream.h>
  2.  
  3. inline void html( char str[] ) { cout << str << "\n"; }
  4.  
  5. inline void html_( char str[] ) { cout << str; }
  6.  
  7. inline void html_( char c ) { cout << c; }
  8.  
  9. void write_number( const int number )
  10. {
  11.   int number_to_print = number;
  12.   if ( number < 0 )                        // Make +ve
  13.   {
  14.     number_to_print= -number; cout << "-";
  15.   }
  16.   int first_digit  = number_to_print%10;    // Split
  17.   int other_digits = number_to_print/10;    //
  18.   if ( number_to_print >= 10 )              // More than 1 digit
  19.   {
  20.     write_number( other_digits );           // Other digits
  21.   }
  22.   cout << (char) (first_digit + (int) '0'); // First digit
  23. }
  24.  
  25. inline void html_( int n )
  26. {
  27.   write_number( n );
  28. }
  29.  
  30. void main()
  31. {
  32.  html("<TABLE BORDER CELLPADDING=2>");
  33.  
  34.  html("<TH ALIGN=LEFT> Character</TH>");
  35.  html("<TH ALIGN=LEFT> Represent by sequence </TH>");
  36.  html("<TH ALIGN=LEFT> Character</TH>");
  37.  html("<TH ALIGN=LEFT> Represent by sequence </TH>");
  38.  html("<TH ALIGN=LEFT> Character</TH>");
  39.  html("<TH ALIGN=LEFT> Represent by sequence </TH>");
  40.  
  41.  const int start=33;
  42.  for( int i=start; i<=255; i++ )
  43.  {
  44.    if ( (i-start)%3==0 )
  45.    {
  46.       html("");
  47.       html("<TR>");
  48.    }
  49.    html_("<TD ALIGN=LEFT> &#"); html_(i); html(";</TD>");
  50.    html_("<TD ALIGN=LEFT>");
  51.      html_( "<TT>&#"); html_(i); html(";</TT>");
  52.    html_( "<BR></TD>");
  53.  }
  54.  html("</TABLE>");
  55. }
  56.  
  57.